package com.yazi.mxz.common.service.impl;


import javax.annotation.Resource;

import com.myframework.smhj.hibernate.Searching;
import com.myframework.smhj.hibernate.Page;
import com.myframework.smhj.hibernate.dao.BasicService;
import com.myframework.smhj.hibernate.dao.Dao;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.yazi.mxz.common.db.dao.MemberNoticeDao;
import com.yazi.mxz.common.db.dao.NoticeDao;
import com.yazi.mxz.common.entity.ValueFactory;
import com.yazi.mxz.common.entity.beans.MemberNotice;
import com.yazi.mxz.common.service.MemberNoticeService;

@Service("memberNoticeService")
public class MemberNoticeServiceImpl extends BasicService<MemberNotice> implements MemberNoticeService{
	private static Logger log = LoggerFactory.getLogger(MemberNoticeServiceImpl.class);
	
	@Resource
	MemberNoticeDao memberNoticeDao;
	
	@Resource
	NoticeDao noticeDao;

	@Override
	protected Dao<MemberNotice> getDao() {
		return memberNoticeDao;
	}
	
	@Override
	public MemberNotice add(MemberNotice memberNotice) {
		log.debug("add：memberId={},noticeId={}", 
				memberNotice.getId().getMemberId(), memberNotice.getId().getNoticeId());
		ValueFactory.validate(memberNotice);
		return memberNoticeDao.persist(memberNotice);
	}

	@Override
	public void removeByMemberId(long memberId, long[] noticeIds) {
		log.debug("removeByMemberId: memberId={},noticeIds={}", memberId, noticeIds);
		memberNoticeDao.delete(memberId, noticeIds);
		noticeDao.deleteLonely(noticeIds);
	}

	@Override
	public void editStatusToViewed(long memberId) {
		log.debug("editStatusToViewed: memberId={}", memberId);
		memberNoticeDao.update(memberId);
	}

	@Override
	public Page<MemberNotice> listByMemberId(long memberId, Searching si) {
		log.debug("listByMemberId：memberId={}", memberId);
		return memberNoticeDao.listByMemberId(memberId, si);
	}

}
